package com.jms.boot.context;

import com.jms.framework.beans.BeanDefinition;
import com.jms.framework.beans.factory.ObjectFactory;
import com.jms.framework.beans.context.AbstractBeanContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class JmsBootBeanContext extends AbstractBeanContext {

    private static final Logger logger = LogManager.getLogger(JmsBootBeanContext.class);
    private volatile static JmsBootBeanContext instance;
    private JmsBootBeanContext() {

    }

    public static JmsBootBeanContext getInstance() {
        if (instance == null) {
            synchronized (JmsBootBeanContext.class) {
                if (instance == null) {
                    instance = new JmsBootBeanContext();
                }
            }
        }
        return instance;
    }

    @Override
    protected ObjectFactory<?> createSingletonBeanFactory(BeanDefinition beanDefinition) {
        return defaultCreateSingletonBeanFactory(beanDefinition);
    }

    @Override
    protected BeanDefinition createBeanDefinition(Class<?> clazz) {
        return defaultCreateBeanDefinition(clazz);
    }

    @Override
    public void init() {
        logger.info("JmsBoot bean context starts initializing.");
        super.init();
        logger.info("JmsBoot bean context initialization is complete.");
    }

    @Override
    public void destroy() {
        logger.info("JmsBoot bean context starts destroying.");
        super.destroy();
        logger.info("JmsBoot bean context destruction is complete.");
    }
}
